"""
@version:python3
@author:ll
@file:03-QObject-类型判定与对象删除.py
@time:2022/2/8 20:23
"""
from PyQt5.Qt import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("")
        self.resize(500, 500)
        self.setup_ui()

    def setup_ui(self):  # 添加子控件以及子控件的配置操作
        # self.QObject_test()
        self.QObject_anli()
    def QObject_test(self): # API
        obj = QObject()
        w = QWidget()
        btn = QPushButton()
        label = QLabel()

        objs = [obj,w,btn,label]
        for o in objs:
            # print(o.isWidgetType())
            # print(o.inherits("QWidget"))
            print(o.inherits("QPushButton"))

    def QObject_anli(self): # 创建一个窗口, 包含多个QLabel或其他控件，将包含在窗口内所有的QLabel控件, 设置背景色cyan
        label1 = QLabel(self)
        label1.setText("社会我顺哥")
        label1.move(100,100)

        label2 = QLabel(self)
        label2.setText("人狠话不多")
        label2.move(150, 150)

        btn = QPushButton(self)
        btn.setText("btn")
        btn.move(200,200)

        # for widget in self.findChildren(QLabel):
        #     print(widget)

        for widget in self.children():
            # print(widget.isWidgetType())
            if widget.inherits("QLabel"):
                # print("yes")
                widget.setStyleSheet("background-color:cyan;")


if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    window = Window()
    window.show()

    sys.exit(app.exec_())
